package controllers

import "git.oschina.net/hfwb/tianqi.git/tq/model"

type Station struct {
    base
}

func (this *Station) GetAll() {

    type CityModel struct {
        Name string
        List []*model.Station
    }
    result := []*CityModel{}
    tmpMap := map[string]*CityModel{}

    m := model.NewStation()
    if list, err := m.GetAll(); err != nil {
        this.Response(err)
    } else {
        for _, v := range list {
            var city *CityModel
            if c, ok := tmpMap[v.CityName]; ok {
                city = c
            } else {
                city = new(CityModel)
                city.Name = v.CityName
                city.List = []*model.Station{}
                tmpMap[v.CityName] = city
                result = append(result, city)
            }
            city.List = append(city.List, v)
        }
        this.Response(result)
    }
}
